package com.motong.gongdan.vo.system.device.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Objects;

@ApiModel("设备状态占比")
@Data
public class DeviceStatusRateVo {

    @ApiModelProperty("设备id")
    private String deviceId;

    @ApiModelProperty("设备名称")
    private String deviceName;

    @ApiModelProperty("设备编号")
    private String deviceSn;

    @ApiModelProperty("状态占比")
    private String rate;

    @ApiModelProperty("状态名称")
    private String statusName;

    @ApiModelProperty("时间间隔(秒)")
    private BigDecimal duration;

    @ApiModelProperty("时间间隔(分,秒)")
    private String durationCN;

    public DeviceStatusRateVo setDuration(BigDecimal duration) {
        if (Objects.nonNull(duration)) {
            BigDecimal[] bigDecimals = duration.divideAndRemainder(BigDecimal.valueOf(60L));
            String minute = bigDecimals[0].toPlainString();
            String second = bigDecimals[1].toPlainString();
            this.durationCN = String.format("%s分%s秒", minute, second);
        }
        this.duration = duration;
        return this;
    }
}
